/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package caintra.Sapra.Pantalla.Abono;

import caintra.Sapra.Internacional.DBManager;
import caintra.Sapra.Model.Abono;
import caintra.Sapra.Model.MovimientosCaintra;
import java.util.List;

/**
 *
 * @author cobain
 */
public class AbonoQuery {
    public boolean insertMovimiento(MovimientosCaintra abono){
        String sql="";
        try {
            sql="insert into movimientos_caintra(fk_empresaId, fk_periodoId, Cantidad, Comentarios, usuarioId, isAbono) values ("
                    + ""+abono.getFk_empresaId()+","
                    + "'"+abono.getFk_periodoId()+"',"
                    + ""+abono.getCantidad()+","
                    + "'"+abono.getComentarios()+"',"
                    + ""+abono.getUsuarioId()+","
                    + ""+abono.getIsAbono()+""
                    + ")";
                    int x=DBManager.insert(sql);
                    if(x <= 0){
                        return false;
                    }

        } catch (Exception e) {
            return false;
        }
       return true;
    }


    public boolean deleteMovimiento(int abonoid){
        String sql="";
        try {
            sql="DELETE FROM movimientos_caintra WHERE movimientos_caintra_id="+abonoid;
            System.out.println(sql);
            DBManager.Update(sql);

        } catch (Exception e) {
            return false;
        }
        return true;

    }


    public List<MovimientosCaintra> getMovimiento(int fk_empId, int fk_per){
        List<MovimientosCaintra> lista;
        try{
            String sql="SELECT m.*,u.login AS login FROM movimientos_caintra m"
                    + " INNER JOIN usuario u"
                    + " ON m.usuarioId = u.usuarioId"
                    + " WHERE m.fk_empresaId="+fk_empId+" and m.fk_periodoId="+fk_per;
            System.out.println(sql);
           lista=DBManager.getQuery(MovimientosCaintra.class,sql);

        } catch (Exception e) {
            return null;
        }
        return lista;

    }

}
